home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / envman.lha / EnvManager / rcs / envman.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  5.3 KB  |  217 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.1; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.1
  10. date    96.08.23.16.57.28;    author dlorre;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @EnvManager : Gestionnaire d'Environnement
  17. Auteur : Dominique Lorre
  18. @
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @#include <exec/types.h>
  27. #include <dos/dos.h>
  28. #include <dos/dosextens.h>
  29. #include <dos/exall.h>
  30. #include <dos/var.h>
  31. #include <graphics/gfxbase.h>
  32. #include <diskfont/diskfont.h>
  33. #include <string.h>
  34. #include <stdio.h>
  35.  
  36. #include <cxxproto/exec.h>
  37. #include <cxxproto/graphics.h>
  38. #include <cxxproto/dos.h>
  39. #include <cclib/debug_protos.h>
  40.  
  41. #include <screen.h>
  42. #include <locale.h>
  43.  
  44. #include "envdef.h"
  45. #include "enventry.h"
  46. #include "envwin.h"
  47. #include "envopt.h"
  48.  
  49.  
  50. nlist *envlist ;
  51. nlist *envarclist ;
  52. nlist *envloclist ;
  53.  
  54. LONG envsize = 0 ;
  55. LONG envlocsize = 0 ;
  56. Library *ConsoleDevice ;
  57. Process *proc ;
  58. screen *ns ;
  59. char NormalName[MAXFONTNAME] = "Times.font" ;
  60. char TinyName[MAXFONTNAME] = "Helvetica.font" ;
  61. TTextAttr Normal = { "Times.font", 11, 0, 0, 0};
  62. TTextAttr Tiny = {"Helvetica.font", 9, 0, 0, 0} ;
  63.  
  64. catalog *ecat ;
  65.  
  66.  
  67. envwindow *ew ;
  68.  
  69. void _STI_4500_initcat()
  70. {
  71.         ecat = new catalog("envman.catalog", "english", NULL) ;
  72. }
  73.  
  74.  
  75. void _STD_4500_closecat()
  76. {
  77.     delete ecat ;
  78. }
  79.  
  80.  
  81. void initlist(STRPTR name, UWORD flags, nlist *l, char type, char *prevpath)
  82. {
  83. ExAllData       *EAData ;
  84. ExAllData       *ead ;
  85. ExAllControl    *eac ;
  86. LONG            more ;
  87. char            locname[MAXSIZE] ;
  88. char            fname[MAXSIZE] ;
  89. char            *contents ;
  90. char            path[MAXSIZE] ;
  91. BPTR            clef ;
  92. BPTR            file ;
  93.  
  94.  
  95.     strcpy(path, name) ;
  96.     if (prevpath) {
  97.         AddPart(path, prevpath, MAXSIZE-1) ;
  98.     }
  99.     clef = Lock(path, ACCESS_READ);
  100.  
  101.     EAData = new ExAllData[MAXENTRIES] ;
  102.  
  103.     eac = (ExAllControl *)AllocDosObject(DOS_EXALLCONTROL,NULL);
  104.  
  105.     eac->eac_Entries = MAXENTRIES ;
  106.     eac->eac_MatchString = NULL ;
  107.     eac->eac_MatchFunc = NULL ;
  108.     eac->eac_LastKey = 0;
  109.     do {
  110.         more = ExAll(clef, EAData, sizeof(ExAllData)*MAXENTRIES, ED_SIZE, eac);
  111.         if ((!more) && (IoErr() != ERROR_NO_MORE_ENTRIES)) {
  112.             // ExAll failed abnormally
  113.             break;
  114.         }
  115.         if (eac->eac_Entries == 0) {
  116.             // ExAll failed normally with no entries
  117.             continue;                   // ("more" is *usually* zero)
  118.         }
  119.         ead = EAData;
  120.         do {
  121.             if (prevpath) {
  122.                 strcpy(locname, prevpath) ;
  123.                 AddPart(locname, ead->ed_Name, MAXSIZE-1) ;
  124.             }
  125.             else
  126.                 strncpy(locname, ead->ed_Name, MAXSIZE-1) ;
  127.             if (ead->ed_Type>0) {
  128.                 initlist(name, flags, l, type, locname) ;
  129.             }
  130.             else {
  131.                 contents = new char[ead->ed_Size+1] ;
  132.                 strcpy(fname, name) ;
  133.                 AddPart(fname, locname, MAXSIZE-1) ;
  134.                 file = Open(fname, MODE_OLDFILE) ;
  135.                 if (file) {
  136.                     Read(file, contents, ead->ed_Size) ;
  137.                     Close(file) ;
  138.                     if (!(flags & GVF_SAVE_VAR))
  139.                         envsize += ead->ed_Size ;
  140.                     l->enqueue(new enventry(locname, contents, ead->ed_Size, type)) ;
  141.                 }
  142.                 delete contents ;
  143.             }
  144.             ead = ead->ed_Next;
  145.         } while (ead);
  146.  
  147.     } while (more);
  148.  
  149.     FreeDosObject(DOS_EXALLCONTROL,eac);
  150.     delete EAData ;
  151.     UnLock(clef);
  152. }
  153.  
  154. void initloclist(Process *p)
  155. {
  156. LocalVar    *lv ;
  157. char        locname[MAXSIZE] ;
  158.  
  159.     lv = (LocalVar *)p->pr_LocalVars.mlh_Head ;
  160.     while (lv->lv_Node.ln_Succ) {
  161.         strcpy(locname, lv->lv_Node.ln_Name) ;
  162.         envloclist->enqueue(new enventry(locname, lv->lv_Value,
  163.             lv->lv_Len, (lv->lv_Node.ln_Type & LV_ALIAS)?ALIAS_TYPE:LOCAL_TYPE)) ;
  164.         envlocsize += sizeof(LocalVar) + lv->lv_Len ;
  165.  
  166.         lv = (LocalVar *)lv->lv_Node.ln_Succ ;
  167.     }
  168. }
  169.  
  170.  
  171. void main(void)
  172. {
  173. IORequest   ioreq ;
  174.  
  175.  
  176.     ns = new screen("Workbench") ;
  177.     if (!OpenDevice("console.device", -1, (IORequest *)&ioreq, 0)) {
  178.         ConsoleDevice = (Library *)ioreq.io_Device ;
  179.         proc = (Process *)FindTask(NULL) ;
  180.  
  181.         envlist = new nlist ;
  182.         initlist("ENV:", GVF_GLOBAL_ONLY|GVF_BINARY_VAR|GVF_DONT_NULL_TERM, envlist, GLOBAL_TYPE, NULL) ;
  183.         envarclist = new nlist ;
  184.         initlist("ENVARC:", GVF_GLOBAL_ONLY|GVF_SAVE_VAR|GVF_BINARY_VAR|GVF_DONT_NULL_TERM, envarclist, ARCHIVED_TYPE, NULL) ;
  185.  
  186.         envloclist = new nlist ;
  187.         initloclist(proc) ;
  188.  
  189.         strcpy((char *)NormalName, (char *)ns->screen->Font->ta_Name) ;
  190.         Normal.tta_Name = NormalName ;
  191.         Normal.tta_YSize = ns->screen->Font->ta_YSize ;
  192.         Normal.tta_Style = ns->screen->Font->ta_Style ;
  193.         Normal.tta_Flags = ns->screen->Font->ta_Flags ;
  194.  
  195.         strcpy((char *)TinyName, (char *)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name) ;
  196.         Tiny.tta_Name = TinyName ;
  197.         Tiny.tta_YSize = GfxBase->DefaultFont->tf_YSize ;
  198.         Tiny.tta_Style = GfxBase->DefaultFont->tf_Style ;
  199.         Tiny.tta_Flags = GfxBase->DefaultFont->tf_Flags ;
  200.  
  201.  
  202.         ew = new envwindow(10, 10, 500, 120) ;
  203.         ew->open(ns) ;
  204.         ew->eventloop() ;
  205.         ew->close() ;
  206.         delete ew ;
  207.         delete envlist ;
  208.         delete envarclist ;
  209.         delete envloclist ;
  210.  
  211.         CloseDevice((IORequest *)&ioreq) ;
  212.     }
  213.     delete ns ;
  214.  
  215. }
  216. @
  217.